package org.concepts.java.utils;

public class DataUtils {

  /**
   * Prints the array to std out
   * 
   * @param input
   *          input. Can be null or empty
   */
  public static void printArray(int[] input) {
    if (input == null) {
      return;
    }
    System.out.print("[");
    for (int i = 0; i < input.length; i++) {
      System.out.print(input[i] + ((i + 1 < input.length) ? "," : ""));
    }
    System.out.println("]");
  }

  /**
   * Returns an int array of the specified size and with elements whose value is
   * less than or equal to specified maximium value.
   * 
   * @param size
   *          size of the array. Should be 1 or more
   * @param maxValue
   *          maximum value in array. Should be 1 or more
   * @return int[] is never null.
   */
  public static int[] randomInts(int size, int maxValue) {
    if (size < 1 || maxValue < 1) {
      throw new IllegalArgumentException(
          "Size and maxValue should be >= 1. size: " + size + " maxValue: "
              + maxValue);
    }
    int[] data = new int[size];
    for (int ctr = 0; ctr < size; ctr++) {
      data[ctr] = (int) (Math.random() * maxValue);
    }
    return data;
  }
}
